﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using Entity;
using DAL;
using Models;
using System.Data.Linq;
using System.Linq.Expressions;
namespace BAL
{
    public class ExamPaper : BaseBAL<ExamPaperInfo, Models.ExamPaper>
    {
        public static IList<ExamPaperInfo> GetList(int first, int max)
        {
            using (var db = DatabaseHelper.GetDashboardData())
            {
                if (max > 0)
                {
                    return db.GetTable<Models.ExamPaper>().OrderByDescending(p => p.CreateDate).Skip(first).Take(max).Select(t => TransT2ToT1(t)).ToList();
                }
                else
                {
                    return db.GetTable<Models.ExamPaper>().OrderByDescending(p=>p.CreateDate).Select(t => TransT2ToT1(t)).ToList();
                }
            }
        }

        public static IList<ExamPaperInfo> GetList()
        {
            using (var db = DatabaseHelper.GetDashboardData())
            {
                return db.GetTable<Models.ExamPaper>().OrderByDescending(p => p.CreateDate).Select(t => TransT2ToT1(t)).ToList();
            }
        }
        public static int GetExamPaperInfoStatus(int examPaperInfoId)
        {
            using (var db = DatabaseHelper.GetDashboardData())
            {
               IQueryable<int> query=  db.GetTable<Models.ExamPaper>().Where(p => p.Id == examPaperInfoId).Select(p => p.Status);
               if (query != null && query.Count() > 0)
               {
                   foreach (var item in query)
                   {
                       return item;
                   }
               }
               return 1;
            }
        }
       
    }
}

